#
# This module is provided as PLUSLIB_USE_FILE
# It can be INCLUDEd in a project to load the needed compiler and linker
# settings to use Plus library.
#

IF(NOT PLUSLIB_USE_FILE_INCLUDED)
  SET(PLUSLIB_USE_FILE_INCLUDED 1)

  CMAKE_POLICY(PUSH)
  CMAKE_POLICY(SET CMP0012 NEW) # if() recognizes numbers and boolean constants

  IF(@PLUSLIB_IS_INSTALL@)
    MESSAGE(FATAL_ERROR "PlusLib use file is not supported for INSTALL Builds. Please link directly to targets provided by PlusLibTargets.cmake.")
  ENDIF()


  ## Set Plus binary dir path
  SET(PLUSLIB_DIR "@PlusLib_BINARY_DIR@")

  ## Set Plus source dir path
  SET(PLUSLIB_SOURCE_DIR "@PlusLib_SOURCE_DIR@")

  ## Set Plus data dir path
  SET(PLUSLIB_DATA_DIR "@PLUSLIB_DATA_DIR@")

  ## Set Plus executable output path
  SET(PLUS_EXECUTABLE_OUTPUT_PATH "@PLUS_EXECUTABLE_OUTPUT_PATH@")

  ## Set Plus scripts folder path
  SET(PLUSLIB_SCRIPTS_DIR "@PLUSLIB_SCRIPTS_DIR@")

  ## Find ITK
  FIND_PACKAGE(ITK PATHS "@ITK_DIR@" NO_DEFAULT_PATH)
  IF(ITK_FOUND)
    INCLUDE("@ITK_USE_FILE@")
  ELSE()
    MESSAGE(FATAL_ERROR "ITK not found in UsePlusLib.cmake. Please report this to the developers at https://github.com/PlusToolkit/PlusLib.")
  ENDIF()

  ## Find VTK
  FIND_PACKAGE(VTK PATHS "@VTK_DIR@" NO_DEFAULT_PATH)
  IF (VTK_FOUND)
    INCLUDE("@VTK_USE_FILE@")
  ELSE()
    MESSAGE(FATAL_ERROR "VTK not found in UsePlusLib.cmake. Please report this to the developers at https://github.com/PlusToolkit/PlusLib.")
  ENDIF()

  SET(PLUS_USE_OpenIGTLink @PLUS_USE_OpenIGTLink@)
  IF(PLUS_USE_OpenIGTLink)
    SET(OpenIGTLink_DIR "@OpenIGTLink_DIR@")
    FIND_PACKAGE(OpenIGTLink PATHS "@OpenIGTLink_DIR@" NO_MODULE)
    IF(OpenIGTLink_USE_FILE)
      INCLUDE ("@OpenIGTLink_USE_FILE@")
    ENDIF()

    SET(OpenIGTLinkIO_DIR "@OpenIGTLinkIO_DIR@")
    FIND_PACKAGE(OpenIGTLinkIO PATHS "@OpenIGTLinkIO_DIR@" NO_MODULE)
  ENDIF()

  IF(PLUS_USE_TextRecognizer)
    SET(tesseract_DIR "@tesseract_DIR@")
    FIND_PACKAGE(tesseract NO_MODULE)
  ENDIF()

  SET(PLUS_USE_OpenCV @PLUS_USE_OpenCV@)
  IF(PLUS_USE_OpenCV)
    SET(OpenCV_DIR "@OpenCV_DIR@")
    FIND_PACKAGE(OpenCV)
  ENDIF()

  SET(PLUS_USE_SLICER @PLUS_USE_SLICER@)
  IF(PLUS_USE_SLICER)
    SET(SLICER_BIN_DIRECTORY "@SLICER_BIN_DIRECTORY@")
  ENDIF()

  SET(PLUS_USE_IGSIO @PLUS_USE_IGSIO@)
  IF(PLUS_USE_IGSIO)
    SET(IGSIO_DIR "@IGSIO_DIR@")
    FIND_PACKAGE(IGSIO)
  ENDIF()

  # Add include directories needed to use PlusLib library
  # Use a temporary CMake variable to store the list of directory paths
  # (it is required because this way directory names
  # that do not contain space and those that do contain space
  # work equally well).
  SET(PLUSLIB_INCLUDE_DIRS_TEMP "@PLUSLIB_INCLUDE_DIRS@")
  INCLUDE_DIRECTORIES(${PLUSLIB_INCLUDE_DIRS_TEMP})

  # Add link directories needed to use Plus library
  # Use a temporary CMake variable to store the list of directory paths
  # (it is required because this way directory names
  # that do not contain space and those that do contain space
  # work equally well).
  SET(PLUSLIB_LIBRARY_DIRS_TEMP "@PLUSLIB_LIBRARY_DIRS@")
  LINK_DIRECTORIES(${PLUSLIB_LIBRARY_DIRS_TEMP})

  MESSAGE(STATUS "PlusLib use file triggered. In the future, consider linking directly to targets provided by PlusLibTargets.cmake.")

  SET(PLUSLIB_BUILD_SHARED_LIBS @BUILD_SHARED_LIBS@)

  ## Find SVN
  SET(SVN_FOUND @Subversion_FOUND@)
  IF(SVN_FOUND)
    SET(Subversion_SVN_EXECUTABLE "@PLUSLIB_SVN_EXECUTABLE@" CACHE INTERNAL "")
  ENDIF()

  ## Set Plus version
  SET(PLUSLIB_VERSION "@PLUSLIB_VERSION@")
  SET(PLUSLIB_VERSION_MAJOR @PLUSLIB_VERSION_MAJOR@)
  SET(PLUSLIB_VERSION_MINOR @PLUSLIB_VERSION_MINOR@)
  SET(PLUSLIB_VERSION_PATCH @PLUSLIB_VERSION_PATCH@)
  SET(PLUSLIB_PLATFORM @PLUSLIB_PLATFORM@)
  SET(PLUSLIB_REVISION @PLUSLIB_REVISION@)

  ## Set PlusLib commit date
  SET(PLUSLIB_COMMIT_DATE @PLUSLIB_COMMIT_DATE@)
  SET(PLUSLIB_COMMIT_DATE_NO_DASHES @PLUSLIB_COMMIT_DATE_NO_DASHES@)

  ## Set third party lib path variables
  SET(ICCAPTURING_BIN_DIR "@ICCAPTURING_BIN_DIR@")
  SET(NDIOAPI_BINARY_DIR "@NDIOAPI_BINARY_DIR@")
  SET(ULTRASONIX_SDK_BINARY_DIR "@ULTRASONIX_SDK_BINARY_DIR@")
  SET(ATC_TRAKSTAR_BINARY_DIR "@ATC_TRAKSTAR_BINARY_DIR@")
  SET(USDIGITAL_SEI_BINARY_DIR "@USDIGITAL_SEI_BINARY_DIR@")
  SET(NVIDIA_DVP_BINARY_DIR "@NVIDIA_DVP_BINARY_DIR@")

  ## Set Plus use variables
  SET(PLUS_USE_AGILENT @PLUS_USE_AGILENT@)
  SET(PLUS_USE_3dConnexion_TRACKER @PLUS_USE_3dConnexion_TRACKER@)
  SET(PLUS_USE_aruco @PLUS_USE_aruco@)
  SET(PLUS_USE_Ascension3DG @PLUS_USE_Ascension3DG@)
  SET(PLUS_USE_Ascension3DGm @PLUS_USE_Ascension3DGm@)
  SET(PLUS_USE_BKPROFOCUS_CAMERALINK @PLUS_USE_BKPROFOCUS_CAMERALINK@)
  SET(PLUS_USE_BKPROFOCUS_VIDEO @PLUS_USE_BKPROFOCUS_VIDEO@)
  SET(PLUS_TEST_BKPROFOCUS @PLUS_TEST_BKPROFOCUS@)
  SET(PLUS_USE_BRACHY_TRACKER @PLUS_USE_BRACHY_TRACKER@)
  SET(PLUS_USE_CAPISTRANO_VIDEO @PLUS_USE_CAPISTRANO_VIDEO@)
  SET(PLUS_USE_EPIPHAN @PLUS_USE_EPIPHAN@)
  SET(PLUS_USE_ICCAPTURING_VIDEO @PLUS_USE_ICCAPTURING_VIDEO@)
  SET(PLUS_USE_INTELREALSENSE @PLUS_USE_INTELREALSENSE@)
  SET(PLUS_USE_ATRACSYS @PLUS_USE_ATRACSYS@)
  SET(PLUS_USE_SPINNAKER_VIDEO @PLUS_USE_SPINNAKER_VIDEO@)
  SET(PLUS_USE_INTERSONSDKCXX_VIDEO @PLUS_USE_INTERSONSDKCXX_VIDEO@)
  SET(PLUS_USE_INTERSONARRAYSDKCXX_VIDEO @PLUS_USE_INTERSONARRAYSDKCXX_VIDEO@)
  SET(PLUS_USE_INTERSON_VIDEO @PLUS_USE_INTERSON_VIDEO@)
  SET(PLUS_USE_IntuitiveDaVinci @PLUS_USE_IntuitiveDaVinci@)
  SET(PLUS_USE_MICRONTRACKER @PLUS_USE_MICRONTRACKER@)
  SET(PLUS_USE_MMF_VIDEO @PLUS_USE_MMF_VIDEO@)
  SET(PLUS_USE_NDI @PLUS_USE_NDI@)
  SET(PLUS_USE_NDI_CERTUS @PLUS_USE_NDI_CERTUS@)
  SET(PLUS_USE_NVIDIA_DVP @PLUS_USE_NVIDIA_DVP@)
  SET(PLUS_USE_OpenCV @PLUS_USE_OpenCV@)
  SET(PLUS_USE_OPTICAL_MARKER_TRACKER @PLUS_USE_OPTICAL_MARKER_TRACKER@)
  SET(PLUS_USE_OPTIMET_CONOPROBE @PLUS_USE_OPTIMET_CONOPROBE@)
  SET(PLUS_USE_OPTITRACK @PLUS_USE_OPTITRACK@)
  SET(PLUS_USE_OvrvisionPro @PLUS_USE_OvrvisionPro@)
  SET(PLUS_USE_PHIDGET_SPATIAL_TRACKER @PLUS_USE_PHIDGET_SPATIAL_TRACKER@)
  SET(PLUS_USE_PHILIPS_3D_ULTRASOUND @PLUS_USE_PHILIPS_3D_ULTRASOUND@)
  SET(PLUS_USE_STEALTHLINK @PLUS_USE_STEALTHLINK@)
  SET(PLUS_USE_TELEMED_VIDEO @PLUS_USE_TELEMED_VIDEO@)
  SET(PLUS_USE_THORLABS_VIDEO @PLUS_USE_THORLABS_VIDEO@)
  SET(PLUS_USE_ULTRASONIX_VIDEO @PLUS_USE_ULTRASONIX_VIDEO@)
  SET(PLUS_USE_USDIGITALENCODERS_TRACKER @PLUS_USE_USDIGITALENCODERS_TRACKER@)
  SET(PLUS_USE_VFW_VIDEO @PLUS_USE_VFW_VIDEO@)
  SET(PLUS_USE_OpenCV_VIDEO @PLUS_USE_OpenCV_VIDEO@)
  SET(PLUS_USE_OPENHAPTICS @PLUS_USE_OPENHAPTICS@)
  SET(PLUS_USE_BLACKMAGIC_DECKLINK @PLUS_USE_BLACKMAGIC_DECKLINK@)
  SET(PLUS_USE_V4L2 @PLUS_USE_V4L2@)
  SET(PLUS_USE_TextRecognizer @PLUS_USE_TextRecognizer@)
  SET(PLUS_USE_INFRARED_TEQ1_CAM @PLUS_USE_INFRARED_TEQ1_CAM@)
  SET(PLUS_USE_INFRARED_SEEK_CAM @PLUS_USE_INFRARED_SEEK_CAM@)
  SET(PLUS_USE_INTELREALSENSE_CAM @PLUS_USE_INTELREALSENSE_CAM@)
  SET(PLUS_USE_WITMOTIONTRACKER @PLUS_USE_WITMOTIONTRACKER@)
  SET(PLUS_USE_LEAPMOTION @PLUS_USE_LEAPMOTION@)
  SET(PLUS_USE_MKV_IO @PLUS_USE_MKV_IO@)
  SET(PLUS_USE_VP9 @PLUS_USE_VP9@)
  SET(PLUS_USE_CLARIUS @PLUS_USE_CLARIUS@)
 SET(PLUS_USE_STEAMVR @PLUS_USE_STEAMVR@)

  SET(PLUS_ENABLE_VIDEOSTREAMING @OpenIGTLink_ENABLE_VIDEOSTREAMING@)

  SET(PLUSLIB_DEPENDENCIES @PLUSLIB_DEPENDENCIES@ )

  IF(@PLUS_USE_ULTRASONIX_VIDEO@)
    SET(PLUS_ULTRASONIX_SDK_MAJOR_VERSION @PLUS_ULTRASONIX_SDK_MAJOR_VERSION@)
    SET(PLUS_ULTRASONIX_SDK_MINOR_VERSION @PLUS_ULTRASONIX_SDK_MINOR_VERSION@)
    SET(PLUS_ULTRASONIX_SDK_PATCH_VERSION @PLUS_ULTRASONIX_SDK_PATCH_VERSION@)
  ENDIF()

  IF(@PLUS_USE_OPTITRACK@)
    SET(PLUS_MOTIVE_VERSION_MAJOR @MOTIVE_VERSION_MAJOR@)
    SET(PLUS_MOTIVE_VERSION_MINOR @MOTIVE_VERSION_MINOR@)
    SET(PLUS_MOTIVE_VERSION_PATCH @MOTIVE_VERSION_PATCH@)
  ENDIF()

  MACRO(INCLUDE_PLUSLIB_MS_PROJECTS)
    IF(MSVC)
      IF(@PLUS_BUILD_WIDGETS@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_PlusWidgets@)
      ENDIF()
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusCommon@)
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusUsSimulator@)
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusImageProcessing@)
      IF(@PLUS_USE_USDIGITALENCODERS_TRACKER@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkSEIDrv@)
      ENDIF()
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusDataCollection@)
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusCalibration@)
      IF(@PLUS_RENDERING_ENABLED@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusRendering@)
      ENDIF()
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusVolumeReconstruction@)
      INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkxio@)
      IF(@PLUS_USE_MICRONTRACKER@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_MicronTrackerInterface@)
      ENDIF()
      IF(@PLUS_USE_OpenIGTLink@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusOpenIGTLink@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_vtkPlusServer@)
      ENDIF()
      IF(@PLUS_USE_MMF_VIDEO@)
        INCLUDE_EXTERNAL_MSPROJECT(@vcProj_MfVideoCaptureLibrary@)
      ENDIF()
    ENDIF()
  ENDMACRO()

  MACRO(GROUP_PLUSLIB_MS_PROJECTS GROUPNAME)
    # Ensure targets exist
    INCLUDE_PLUSLIB_MS_PROJECTS()

    IF(MSVC)
      IF(@PLUS_BUILD_WIDGETS@)
        SET_TARGET_PROPERTIES(PlusWidgets PROPERTIES FOLDER ${GROUPNAME})
      ENDIF()
      SET_TARGET_PROPERTIES(vtkPlusCommon PROPERTIES FOLDER ${GROUPNAME})
      SET_TARGET_PROPERTIES(vtkPlusUsSimulator PROPERTIES FOLDER ${GROUPNAME})
      SET_TARGET_PROPERTIES(vtkPlusImageProcessing PROPERTIES FOLDER ${GROUPNAME})
      IF(@PLUS_USE_USDIGITALENCODERS_TRACKER@)
        SET_TARGET_PROPERTIES(vtkSEIDrv PROPERTIES FOLDER ${GROUPNAME})
      ENDIF()
      SET_TARGET_PROPERTIES(vtkPlusDataCollection PROPERTIES FOLDER ${GROUPNAME})
      SET_TARGET_PROPERTIES(vtkPlusCalibration PROPERTIES FOLDER ${GROUPNAME})
      IF(@PLUS_RENDERING_ENABLED@)
        SET_TARGET_PROPERTIES(vtkPlusRendering PROPERTIES FOLDER ${GROUPNAME})
      ENDIF()
      SET_TARGET_PROPERTIES(vtkPlusVolumeReconstruction PROPERTIES FOLDER ${GROUPNAME})
      SET_TARGET_PROPERTIES(vtkxio PROPERTIES FOLDER ${GROUPNAME})
      IF(@PLUS_USE_MICRONTRACKER@)
        SET_TARGET_PROPERTIES(MicronTrackerInterface PROPERTIES FOLDER ${GROUPNAME})
      ENDIF()
      IF(@PLUS_USE_OpenIGTLink@)
        SET_TARGET_PROPERTIES(vtkPlusOpenIGTLink PROPERTIES FOLDER ${GROUPNAME})
        SET_TARGET_PROPERTIES(vtkPlusServer PROPERTIES FOLDER ${GROUPNAME})
      ENDIF()
      IF(@PLUS_USE_MMF_VIDEO@)
        SET_TARGET_PROPERTIES(MfVideoCaptureLibrary PROPERTIES FOLDER ${GROUPNAME})
      ENDIF()
    ENDIF()
  ENDMACRO()

  SET(DOXYGEN_EXECUTABLE "@DOXYGEN_EXECUTABLE@")
  SET(DOXYGEN_DOT_EXECUTABLE "@DOXYGEN_DOT_EXECUTABLE@")
  SET(DOXYGEN_HHC_EXECUTABLE "@DOXYGEN_HHC_EXECUTABLE@")
  SET(PLUSLIB_DOCUMENTATION_TARGET_IN_ALL @DOCUMENTATION_TARGET_IN_ALL@)
  SET(PLUSLIB_BUILD_DOCUMENTATION @BUILD_DOCUMENTATION@)

  CMAKE_POLICY(POP)
ENDIF()
